var bsurl = require('../../../utils/baseUrl.js');
var netUtils = require('../../../utils/netUtils.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hidden: true,
    shopname: "",
    isOpen: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.editTabBar(app.globalData.tabBar);
    var isOpen = "";
    if (app.globalData.userInfo.name1) { isOpen = "(已开通)" };
    this.setData({
      name: app.globalData.userInfo.shopname,
      isOpen: isOpen,
      prestige: app.globalData.userInfo.prestige
    });
  },
   //点击开通栏
  open: function () {
    if (this.data.isOpen) {
      return;
    }
    this.setData({ hidden: false });
  },
  //弹框取消按钮
  cancel: function () {
    this.setData({ hidden: true, shopname: "" });
  },
  //弹框开通按钮
  confirm: function () {
    console.log(this.data.shopname)
    if (!this.data.shopname) {
      wx.showModal({
        title: '提示',
        content: '昵称不能为空',
      });
      return;
    }
    this.setData({ hidden: true });
    var body = app.globalData.userInfo;
    body.name1 = this.data.shopname;
    body.identity = 2;
    netUtils.sendRequest("user/modify.do", body, (data) => {
      this.setData({ isOpen: "(已开通)" })
      wx.showToast({
        title: '开通成功',
        icon: 'success',
        duration: 1500
      });
    });
  },
  //弹框输入框
  input: function (e) {
    this.setData({ shopname: e.detail.value });
  },
  quit: function () {
    wx.redirectTo({
      url: '/pages/login/login',
    })
  }
})